﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;

namespace FBProject.BusinessLogic.FBImport
{
    [Serializable]
    public class MissingColumnsInSourceFileException : Exception
    {
        public IList<string> MissingColumns { get; private set; }

        public MissingColumnsInSourceFileException()
            : base()
        { }

        public MissingColumnsInSourceFileException(string message)
            : base(message)
        { }

        public MissingColumnsInSourceFileException(string message, Exception innerException)
            : base(message, innerException)
        { }

        protected MissingColumnsInSourceFileException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.MissingColumns = new List<string>(info.GetString("MissingColumns").Split(','));
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("MissingColumns", string.Join(",", this.MissingColumns));
        }

        public MissingColumnsInSourceFileException(IList<string> missingColumns)
            : base()
        {
            if (missingColumns == null)
                throw new ArgumentNullException("missingColumns");

            this.MissingColumns = missingColumns;
        }

        public override string Message
        {
            get
            {
                return string.Format(CultureInfo.InvariantCulture, "Cannot find following column{0} in FB source: {1}",
                    this.MissingColumns.Count > 1 ? "s" : string.Empty,
                    string.Join(", ", this.MissingColumns));
            }
        }
    }
}
